//
//  WBBaseTableViewController.swift
//  SainMicroblog
//
//  Created by chenxinju on 16/5/3.
//  Copyright © 2016年 chenxinju-a2. All rights reserved.
//

import UIKit

class WBBaseTableViewController: UITableViewController,WBVisitorViewDelegate {
    
    //定义是否登录过的bool值来判断显示自定义界面 还是系统UIView 调用模型的单例判断Token是否有值
    var isLogin: Bool = WBOauthViewModel.shareInstance.islogin
    //false/true
    
    //定义一个属性来接收访客视图 类型为可选
    var visitloginVIew: WBVisitorView?

    //首次加载视图判断是否登录
    override func loadView() {
        if isLogin { //如果未登录 就显示填充整个View的视图
            super.loadView()
            
        }else { //显示自定义视图
            
            visitloginVIew = WBVisitorView()
            //---------------------
          
            //设置代理为当前控制器
            visitloginVIew?.delegate = self
            view = visitloginVIew
        }
    }
    
    //系统加载View的调用
    override func viewDidLoad() {
        super.viewDidLoad()
        setupNav()//设置导航栏
    }
    
    
   private func setupNav() { //导航栏
      //注册一边
      self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "didshowRegister")
    
     self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "didshowLogin")
    }
}


//===========================实现代理回调
extension WBBaseTableViewController {
    func didshowRegister() {
      //printLog("代理注册点击")
        //跳转到webView界面
        let aouth = WBOauthViewController()
       let nav = UINavigationController(rootViewController: aouth)
        //model到注册界面
        presentViewController(nav, animated: true) { () -> Void in
        }
    }

    //注册点击点击方法代理
    func didshowLogin() {
       printLog("代理登录点击")
    }
}


